combobox: use GtkIcon to render button arrow
authorCosimo Cecchi <cosimoc@gnome.org>
Mon, 21 Dec 2015 22:45:58 +0000 (14:45 -0800)
committerCosimo Cecchi <cosimoc@gnome.org>
Tue, 22 Dec 2015 17:29:43 +0000 (09:29 -0800)
We can now use the newly introduced GtkIcon widget to properly render
the arrow in the combobox with CSS.

gtk/gtkcombobox.c
gtk/theme/Adwaita/_common.scss
gtk/theme/Adwaita/gtk-contained-dark.css
gtk/theme/Adwaita/gtk-contained.css
gtk/ui/gtkcombobox.ui

index d89e89cd05df145f1bde61974bb934faf8e49a51..fd751a2afc1b0c1ece7f80059c3f7f935b9d79e8 100644 (file)
@@ -29,6 +29,7 @@
 #include "gtkcssnodeprivate.h"
 #include "gtkeventbox.h"
 #include "gtkframe.h"
+#include "gtkiconprivate.h"
 #include "gtkbox.h"
 #include "gtkliststore.h"
 #include "gtkmain.h"
  * |[<!-- language="plain" -->
  * combobox
  * ╰── button.combo
+ *     ╰── arrow
  * ]|
  *
  * GtkComboBox has a single CSS node with name combobox. It adds the
  * .combo style class to the button that it contains.
+ * The button also contains another node with name arrow.
  */
 
 
@@ -1017,6 +1020,9 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
    * by arrow size.
    *
    * Since: 2.12
+   *
+   * Deprecated: 3.20: use the standard min-width/min-height CSS properties on
+   *   the arrow node; the value of this style property is ignored.
    */
   gtk_widget_class_install_style_property (widget_class,
                                            g_param_spec_int ("arrow-size",
@@ -1025,7 +1031,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
                                                              0,
                                                              G_MAXINT,
                                                              15,
-                                                             GTK_PARAM_READABLE));
+                                                             GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
 
   /**
    * GtkComboBox:arrow-scaling:
@@ -1033,7 +1039,8 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
    * Sets the amount of space used up by the combobox arrow,
    * proportional to the font size.
    *
-   * Since: 3.2
+   * Deprecated: 3.20: use the standard min-width/min-height CSS properties on
+   *   the arrow node; the value of this style property is ignored.
    */
   gtk_widget_class_install_style_property (widget_class,
                                            g_param_spec_float ("arrow-scaling",
@@ -1042,7 +1049,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
                                                              0,
                                                              2.0,
                                                              1.0,
-                                                             GTK_PARAM_READABLE));
+                                                             GTK_PARAM_READABLE|G_PARAM_DEPRECATED));
 
   /**
    * GtkComboBox:shadow-type:
@@ -1120,6 +1127,7 @@ gtk_combo_box_init (GtkComboBox *combo_box)
   priv->text_renderer = NULL;
   priv->id_column = -1;
 
+  g_type_ensure (GTK_TYPE_ICON);
   gtk_widget_init_template (GTK_WIDGET (combo_box));
 
   gtk_widget_add_events (priv->button, GDK_SCROLL_MASK);
@@ -5030,14 +5038,10 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
 {
   GtkComboBox           *combo_box = GTK_COMBO_BOX (widget);
   GtkComboBoxPrivate    *priv = combo_box->priv;
-  gint                   font_size, arrow_size;
-  PangoContext          *context;
-  PangoFontMetrics      *metrics;
   GtkWidget             *child;
   gint                   child_min, child_nat;
   gint                   but_min, but_nat;
   GtkBorder              padding;
-  gfloat                 arrow_scaling;
   gint                   dummy;
 
   /* https://bugzilla.gnome.org/show_bug.cgi?id=729496 */
@@ -5051,25 +5055,8 @@ gtk_combo_box_get_preferred_width (GtkWidget *widget,
   else
     gtk_widget_get_preferred_width (child, &child_min, &child_nat);
 
-  gtk_widget_style_get (GTK_WIDGET (widget),
-                        "arrow-size", &arrow_size,
-                        "arrow-scaling", &arrow_scaling,
-                        NULL);
-
   get_widget_padding_and_border (widget, &padding);
 
-  context = gtk_widget_get_pango_context (GTK_WIDGET (widget));
-  metrics = pango_context_get_metrics (context,
-                                       pango_context_get_font_description (context),
-                                       pango_context_get_language (context));
-  font_size = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
-                            pango_font_metrics_get_descent (metrics));
-  pango_font_metrics_unref (metrics);
-
-  arrow_size = MAX (arrow_size, font_size) * arrow_scaling;
-
-  gtk_widget_set_size_request (priv->arrow, arrow_size, arrow_size);
-
   gtk_widget_get_preferred_width (priv->button,
                                   &but_min, &but_nat);
 
index de2f23e6d3e44034f33028ebf01fa4f390d24858..63ad6035c697d31b9bcb3871f6d8eb34475d4a7a 100644 (file)
@@ -945,7 +945,6 @@ combobox {
   > button.combo { padding-top: 3px; padding-bottom: 4px; } // Otherwise combos
                                                                            // are bigger then
                                                                            // buttons
-  -GtkComboBox-arrow-scaling: 0.5;
   -GtkComboBox-shadow-type: none;
 
   @include _button_text_shadow;
@@ -963,6 +962,11 @@ combobox {
   &:backdrop:insensitive {
     color: $backdrop_insensitive_color;
   }
+  & arrow {
+    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
+    min-height: 16px;
+    min-width: 16px;
+  }
   & menuitem { text-shadow: none; }
   &.separator.vertical {
     // always disable separators
index 13a7b103dac5149102ae818a4b07939351dca89a..b2022081d2f924b48b5c943820fb6d3b71fbaf6c 100644 (file)
@@ -1511,7 +1511,6 @@ treeview spinbutton entry, treeview spinbutton spinbutton, treeview spinbutton e
  * ComboBoxes *
  **************/
 combobox {
-  -GtkComboBox-arrow-scaling: 0.5;
   -GtkComboBox-shadow-type: none;
   text-shadow: 0 -1px rgba(0, 0, 0, 0.81176);
   -gtk-icon-shadow: 0 -1px rgba(0, 0, 0, 0.81176); }
@@ -1529,6 +1528,10 @@ combobox {
     -gtk-icon-shadow: none; }
   combobox:backdrop:insensitive {
     color: #5d6767; }
+  combobox arrow {
+    -gtk-icon-source: -gtk-icontheme("pan-down-symbolic");
+    min-height: 16px;
+    min-width: 16px; }
   combobox menuitem {
     text-shadow: none; }
   combobox.separator.vertical {
index fc1734a164fd084335dc63f1cfde9fa1c6a081ed..963ae0d536a643a534f5c978e5edd4e192957537 100644 (file)
@@ -1511,7 +1511,6 @@ treeview spinbutton entry, treeview spinbutton spinbutton, treeview spinbutton e
  * ComboBoxes *
  **************/
 combobox {
-  -GtkComboBox-arrow-scaling: 0.5;
   -GtkComboBox-shadow-type: none;
   text-shadow: 0 1px rgba(255, 255, 255, 0.76923);
   -gtk-icon-shadow: 0 1px rgba(255, 255, 255, 0.76923); }
@@ -1529,6 +1528,10 @@ combobox {
     -gtk-icon-shadow: none; }
   combobox:backdrop:insensitive {
     color: #c3c3c0; }
+  combobox arrow {
+    -gtk-icon-source: -gtk-icontheme("pan-down-symbolic");
+    min-height: 16px;
+    min-width: 16px; }
   combobox menuitem {
     text-shadow: none; }
   combobox.separator.vertical {
index ad4d5bd2c34f304ffbe5667d3bfd5a284200b8af..b6f35151eaebbbed99a547795d9b1e36db93d4f4 100644 (file)
@@ -10,9 +10,9 @@
           <object class="GtkBox">
             <property name="visible">1</property>
             <child>
-              <object class="GtkImage" id="arrow">
+              <object class="GtkIcon" id="arrow">
                 <property name="visible">1</property>
-                <property name="icon-name">pan-down-symbolic</property>
+                <property name="css_name">arrow</property>
               </object>
               <packing>
                 <property name="pack_type">end</property>